package reference;

import java.lang.ref.PhantomReference;
import java.lang.ref.ReferenceQueue;

/**
 * @author zhangxin
 * @date 2020/8/28
 */
public class PhantomtTest {

    public static void main(String[] args) {
        TestObject object = new TestObject();

        ReferenceQueue<Object> objectReferenceQueue = new ReferenceQueue<>();
        PhantomReference<TestObject> testObjectPhantomReference = new PhantomReference<>(object, objectReferenceQueue);

        System.out.println(objectReferenceQueue.poll());

        object = null;
        System.gc();
        System.runFinalization();

        System.gc();
        System.runFinalization();

        System.out.println(objectReferenceQueue.poll());
    }
}
